using System;
using System.Xml.XPath;

namespace AutoUpdateEngine.Xml
{
    public class AppPartBuilder
    {
        public AppPartBuilder(XPathNavigator appPartXml)
        {
            if (appPartXml.LocalName != "appPart")
                throw new ArgumentException("the element must be a type of appPart");

            this.appPartXml = appPartXml;
        }

        public AppPart Build()
        {
            AppPart part = new AppPart();

            appPartXml.MoveToChild("fileName", "");
            //trim is very important
            part.FileName = appPartXml.InnerXml.Trim();

            appPartXml.MoveToNext("localDirect", "");
            part.LocalDirect = appPartXml.InnerXml.Trim();

            appPartXml.MoveToNext("remoteDirect", "");
            part.RemoteDirect = appPartXml.InnerXml.Trim();

            appPartXml.MoveToNext("oldFileName", "");
            part.OldFileName = appPartXml.InnerXml.Trim();

            return part;
        }
        XPathNavigator appPartXml;
    }

}
